<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约订单管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">

                    <!--控制组件-->
                    <div class="filter-container">

                        <!--日期选择组件-->
                        <el-date-picker
                                v-model="pagination.date"
                                type="daterange"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                default-value="2020-04-15">
                        </el-date-picker>

                        <!--预约类型-->
                        <template>
                            <el-select v-model="pagination.visitedStatus" placeholder="请选择【预约状态】">
                                <el-option
                                        v-for="item in select_visitedStatus"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                        </template>

                        <!--预约状态-->
                        <template>
                            <el-select v-model="pagination.orderType" placeholder="请选择【预约类型】">
                                <el-option
                                        v-for="item in select_orderType"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                        </template>
                        <el-input placeholder="会员姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>

                    <!--表格部分-->
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="memberName" label="会员姓名" align="center"></el-table-column>
                        <el-table-column prop="phoneNumber" label="电话号码" align="center"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期" :formatter="dateFormat" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center">
                            <template slot-scope="scope">
                                <span>{{scope.row.orderStatus}}</span>
                                <el-switch
                                    v-model=scope.row.orderStatus
                                    active-color="#13ce66"
                                    inactive-color="#ff4949"
                                    active-value="未到诊"
                                    inactive-value="已到诊"
                                    @change="change(scope.row.id,scope.row.orderStatus)">
                                </el-switch>
                            </template>
                        </el-table-column>
                        <el-table-column prop="setmralName" label="套餐名称" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <!--分页组件-->
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page.sync="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>

                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px" :rules="rules" :model="formData" ref="dataAddForm">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号码">
                                                        <el-input v-model="formData.phoneNumber"/>
                                                    </el-form-item>
                                                </el-col>
                                                <span>预约日期</span>
                                                <el-date-picker
                                                    v-model="formData.orderDate"
                                                    type="date"
                                                    placeholder="选择日期"
                                                    value-format="yyyy-MM-dd">
                                                </el-date-picker>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名" prop="memberName">
                                                        <el-input v-model="formData.memberName"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>

                                    <!--套餐信息-->
                                    <el-tab-pane label="套餐信息" name="second">
									<div class="checkScrol">
                                        <table class="datatable">
                                            <thead>
                                            <tr>
                                                <th>选择</th>
                                                <th>套餐编码</th>
                                                <th>套餐名称</th>
                                                <th>套餐说明</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr v-for="c in tableData">
                                                <td>
                                                    <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                                </td>
                                                <td><label :for="c.id">{{c.code}}</label></td>
                                                <td><label :for="c.id">{{c.name}}</label></td>
                                                <td><label :for="c.id">{{c.remark}}</label></td>
                                            </tr>
                                            </tbody>
                                        </table>
									</div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="编辑检查组" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-col :span="12">
                                                        <el-form-item label="姓名" prop="memberName" >
                                                            <el-input v-model="formData.memberName" :disabled="true"/>
                                                        </el-form-item>
                                                    </el-col>
                                                </el-col>
                                                <span>预约日期</span>
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期"
                                                        value-format="yyyy-MM-dd">
                                                </el-date-picker>
                                            </el-row>
                                            <el-row>
                                                预约类型
                                                <el-select v-model="formData.orderType" placeholder="请选择【预约类型】">
                                                    <el-option
                                                            v-for="item in select_orderType"
                                                            :key="item.value"
                                                            :label="item.label"
                                                            :value="item.value">
                                                    </el-option>
                                                </el-select>
                                                预约状态
                                                <el-select v-model="formData.orderStatus" placeholder="请选择【预约状态】">
                                                    <el-option
                                                            v-for="item in select_visitedStatus"
                                                            :key="item.value"
                                                            :label="item.label"
                                                            :value="item.value">
                                                    </el-option>
                                                </el-select>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>

                                    <!--套餐信息-->
                                    <el-tab-pane label="套餐信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>套餐编码</th>
                                                    <th>套餐名称</th>
                                                    <th>套餐说明</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="c in tableData">
                                                    <td>
                                                        <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                                    </td>
                                                    <td><label :for="c.id">{{c.code}}</label></td>
                                                    <td><label :for="c.id">{{c.name}}</label></td>
                                                    <td><label :for="c.id">{{c.remark}}</label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:10,
                    total:100,
                    queryString:null,
                    date:null,
                    visitedStatus:null,
                    orderType:null
                },
                dataList: [],//列表数据
                formData: {},//表单数据
                tableData:[],//新增和编辑表单中对应的检查项列表数据
                setmealIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
                select_orderType: [{//搜索位置的下拉菜单
                    value: '微信预约',
                    label: '微信预约'
                }, {
                    value: '电话预约',
                    label: '电话预约'
                }, {
                    value: null,
                    label: '我全都要'
                }],
                select_visitedStatus: [{//搜索位置的下拉菜单
                    value: '未到诊',
                    label: '未到诊'
                }, {
                    value: '已到诊',
                    label: '已到诊'
                }, {
                    value: null,
                    label: '我全都要'
                }],

                //校验规则
                rules: {
                    memberName: [{ required: true, message: '项目名称为必填项', trigger: 'blur' }]
                }
            },
            created() {
                this.findPage();
            },
            methods: {
                dateFormat:function(row, column) {
                    var date = row[column.property];
                    return date.substring(0,10);
                },
                //编辑
                handleEdit() {

                    axios.post("/order/edit.do?setmealIds="+this.setmealIds,this.formData).then((res =>{

                        if(res.data.flag){
                            //成功就关闭窗口
                            this.dialogFormVisible = false;
                            //成功后刷新页面
                            this.findPage();
                            //设置弹出的提示
                            this.$message({
                                message:res.data.message,
                                type:'true'
                            })
                        }else {
                            this.$message.error("" + res.data.message +"【"+ res.data.data + "】")
                        }
                    }))

                },
                //添加
                handleAdd () {

                    this.$refs['dataAddForm'].validate(valid=> {

                        if (valid) {

                            //校验通过
                            axios.post("/order/add.do?setmealIds="+this.setmealIds,this.formData).then((res =>{

                                if(res.data.flag){

                                    //成功就关闭窗口
                                    this.dialogFormVisible = false;
                                    //成功后刷新页面
                                    this.findPage();
                                    //设置弹出的提示
                                    this.$message({
                                        message:res.data.message,
                                        type:'true'
                                    })
                                }else {
                                    this.$message.error("" + res.data.message +"【"+ res.data.data + "】")
                                }
                            }))
                        }else {
                            this.$message.error("校验失败")
                        }
                    })
                },
                //分页查询
                findPage() {
                    axios.post("/order/findPage.do?",this.pagination).then((res =>{
                        this.pagination.total = res.data.total;
                        this.dataList = res.data.rows;
                    }))

                },
                // 重置表单
                resetForm() {
                    this.formData = {};
                    this.tableData = [];
                    this.setmealIds = [];
                    this.activeName = 'first';
                },
                // 弹出添加窗口
                handleCreate() {

                    this.dialogFormVisible = true;
                    this.resetForm();

                    axios.post("/setmeal/findAll.do").then((res =>{

                        if(res.data.flag){
                            this.tableData = res.data.data;
                        }else {
                            this.$message.error(res.message)
                        }
                    }))

                },
                // 弹出编辑窗口
                handleUpdate(row) {
                    this.dialogFormVisible4Edit = true;

                    axios.get("/order/findById.do?id=" + row.id).then((resp) => {

                        if(resp.data.flag){
                            this.formData = resp.data.data;
                            this.setmealIds = resp.data.data.setmealIds;
                        }else {
                            this.$message.error("" + resp.data.message +"【"+ resp.data.data + "】")
                        }
                    });

                    axios.post("/setmeal/findAll.do").then((res =>{

                        if(res.data.flag){
                            this.tableData = res.data.data;
                        }else {
                            this.$message.error(res.message)
                        }
                    }))
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    this.$confirm('这会导致该项永久删除，你确定吗?', '警告', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {

                        axios.get("/order/deleteById.do?id=" + row.id).then((resp) => {
                            if(resp.flag){
                                this.$message({
                                    type: 'success',
                                    message: '删除成功'
                                });
                                this.findPage();
                            }else {
                                this.$message.error("" + res.data.message +"【"+ res.data.data + "】")
                            }

                        }).catch((r) => {
                            showMessage1(r,this);
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '操作取消'
                        });
                    });
                },
                //快捷更改到诊状态
                change(id,status){
                    this.$confirm('你确定用户的预约状态改变了吗?', '警告', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {

                        var param = {
                            id : id,
                            status : status
                        };

                        axios.post("/order/editVisitedStatus.do",param).then((resp) => {
                            if(resp.flag){
                                this.$message({
                                    type: 'success',
                                    message: '修改成功'
                                });
                                this.findPage();
                            }else {
                                this.$message.error("" + res.data.message +"【"+ res.data.data + "】")
                            }

                        }).catch((r) => {
                            showMessage1(r,this);
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '操作取消'
                        });
                    });
                }
            }
        })
    </script>
</html>
